<?php /*
	
*/ ?>
<?php include("inc/head.inc.php") ?>
<body>
<table width="824" border="0" cellpadding="0" cellspacing="0"  align="center">
  
  <tr>
    <td class="headerclass"><?php include(INC."top.inc.php") ?></td>
  </tr>
  <tr>
    <td valign="top" class="maincontainer">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr><td valign="top"class="leftmenuback" width="235px;"><?php include(INC."left.inc.php") ?></td>
        <td valign="top">
			<div class="pageheader">Categories</div>
			
			<?php
	  	$sql="SELECT tblprodcategory.*, tblprodcategorydesc.* FROM `tblprodcategory` INNER JOIN `tblprodcategorydesc` ON tblprodcategory.intcategoryid = tblprodcategorydesc.intcatid  where tblprodcategory.intparentid=0 ORDER BY `intsortorder` ASC";
		$res=$n02586916_db->select($sql);
		if(count($res)>0) {	
			for($i=0;$i<count($res);$i++) {
				$cat_id= $res[$i]['intcategoryid'];
				$sql5="select * from tblproducts where intcategoryid='$cat_id' and intstatus=0";
				$resc=$n02586916_db->select($sql5);
				if($resc){$cnt=count($resc);}else{$cnt=0;}		
					if (file_exists("images/cat/".$res[$i]['varcategoryimage'])) {
						$image = "images/cat/".$res[$i]['varcategoryimage'];
					} else {
						$image = "images/cat/noimage.jpg";
					}
					
					//select subcats for primary cat
				$subsql = "SELECT tblprodcategory.*, tblprodcategorydesc.* FROM `tblprodcategory` INNER JOIN `tblprodcategorydesc` ON tblprodcategory.intcategoryid = tblprodcategorydesc.intcatid  where tblprodcategory.intparentid=$cat_id ORDER BY `intsortorder` ASC";
				$subresults=$n02586916_db->select($subsql);
				if(count($subresults)>0) {
				$subcatlist = "";
					for($q=0;$q<count($subresults);$q++) {
						$sql5="select * from tblproducts where intcategoryid=".$subresults[$q]['intcategoryid']." and intstatus=0";
						$cres=$n02586916_db->select($sql5);
						if($cres){$cnt=count($cres);}else{$cnt=0;}
						$subcatlist=$subcatlist."<li><a href=\"category.php?intcatid=".$subresults[$q]['intcategoryid']."\">".stripslashes($subresults[$q]['varcategoryname'])." ($cnt items)</a></li>";
					}
				} else { $subcatlist = "No Sub Categories"; }
					
echo "<div id=\"catlistblock\"><div id=\"catlistheader\"><a href=\"category.php?intcatid=$cat_id\">".stripslashes($res[$i]['varcategoryname'])."</a></div><div id=\"catlistcontent\"><div style=\"float:left;padding-right:10px;padding-bottom:3px;\"><img src=\"$image\" border=\"0\" /></div>This category contains <strong>$cnt</strong> products.<br /><br /><a href=\"category.php?intcatid=$cat_id\">Click Here to view the products</a><br /><br /><strong>Sub-Categories within this Category</strong><ul>$subcatlist</ul></div></div>";
			
			}
		}
			?>
			
			
		</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td><?php include "inc/bottom.inc.php"; ?></td>
  </tr>
</table>
</body>
</html>
